1
|
|
|
import { |
2
|
|
|
SET_SELECTION, |
3
|
|
|
SELECT_ALL, |
4
|
|
|
DESELECT_ALL, |
5
|
|
|
NO_EVENT, |
6
|
|
|
SELECT_ROW, |
7
|
|
|
DESELECT_ROW |
8
|
|
|
} from '../../../constants/ActionTypes'; |
9
|
|
|
|
10
|
|
|
export const selectRow = ({ stateKey, rowId }) => ({ |
11
|
|
|
type: SELECT_ROW, |
12
|
|
|
stateKey, |
13
|
|
|
rowId |
14
|
|
|
}); |
15
|
|
|
|
16
|
|
|
export const deselectRow = ({ stateKey, rowId }) => ({ |
17
|
|
|
type: DESELECT_ROW, |
18
|
|
|
stateKey, |
19
|
|
|
rowId |
20
|
|
|
}); |
21
|
|
|
|
22
|
|
|
export const selectAll = ({ data, stateKey }) => { |
23
|
|
|
|
24
|
|
|
if (!data) { |
25
|
|
|
return {}; |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
const keys = data.currentRecords.map((row) => row._key); |
29
|
|
|
|
30
|
|
|
const selection = keys.reduce((obj, k) => { |
31
|
|
|
obj[k] = true; |
32
|
|
|
return obj; |
33
|
|
|
}, {}); |
34
|
|
|
|
35
|
|
|
return { type: SELECT_ALL, selection, stateKey }; |
36
|
|
|
}; |
37
|
|
|
|
38
|
|
|
export const deselectAll = ({ stateKey }) => ({ |
39
|
|
|
type: DESELECT_ALL, stateKey |
40
|
|
|
}); |
41
|
|
|
|
42
|
|
|
export const setSelection = ({ |
43
|
|
|
id, defaults = {}, modes = {}, stateKey, index |
44
|
|
|
}) => { |
45
|
|
|
|
46
|
|
|
const allowDeselect = defaults.allowDeselect; |
47
|
|
|
const clearSelections = defaults.mode === modes.checkboxSingle |
48
|
|
|
|| defaults.mode === modes.single; |
49
|
|
|
|
50
|
|
|
if (!defaults.enabled) { |
51
|
|
|
/* eslint-disable no-console */ |
52
|
|
|
console.warn('Selection model has been disabled'); |
53
|
|
|
/* eslint-enable no-console */ |
54
|
|
|
return { type: NO_EVENT }; |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
if (defaults.mode === modes.single) { |
58
|
|
|
return { |
59
|
|
|
type: SET_SELECTION, |
60
|
|
|
id, |
61
|
|
|
clearSelections, |
62
|
|
|
allowDeselect, |
63
|
|
|
index, |
64
|
|
|
stateKey |
65
|
|
|
}; |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
else if (defaults.mode === modes.multi) { |
69
|
|
|
return { type: SET_SELECTION, id, allowDeselect, index, stateKey }; |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
else if (defaults.mode === modes.checkboxSingle |
|
|
|
|
73
|
|
|
|| defaults.mode === modes.checkboxMulti) { |
74
|
|
|
return { |
75
|
|
|
type: SET_SELECTION, |
76
|
|
|
id, |
77
|
|
|
clearSelections, |
78
|
|
|
allowDeselect, |
79
|
|
|
index, |
80
|
|
|
stateKey |
81
|
|
|
}; |
82
|
|
|
} |
83
|
|
|
}; |
84
|
|
|
|
This check looks for functions where a
return
statement is found in some execution paths, but not in all.Consider this little piece of code
The function
isBig
will only return a specific value when its parameter is bigger than 5000. In any other case, it will implicitly returnundefined
.This behaviour may not be what you had intended. In any case, you can add a
return undefined
to the other execution path to make the return value explicit.